package cn.zyjblogs.starter.minio.autoconfigure;

import cn.zyjblogs.starter.minio.config.MinioProperties;
import cn.zyjblogs.starter.minio.service.MinioService;
import io.minio.MinioClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({MinioProperties.class})
public class MinioAutoConfiguration {

    /**
     * 创建minio客户端
     *
     * @param minioProperties minio的配置参数
     * @return io.minio.MinioClient
     * @author daiweixing
     * @date 2021/11/3 10:35
     */
    @Bean
    public MinioClient minioClient(MinioProperties minioProperties) {
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }

    /**
     * 实例化IMinioService
     *
     * @param minioClient minio客户端
     * @return cn.com.hatechframework.starter.minio.service.IMinioService
     * @author daiweixing
     * @date 2021/11/3 10:35
     */
    @Bean
    public MinioService minioService(MinioClient minioClient, MinioProperties minioProperties) {
        return new MinioService(minioClient, minioProperties);
    }

}
